//科室管理的全局变量
var gongyingshangnew = {
	url: {
	    zdGongyingshangURL:function(){
			return path + '/zidian/getZdGongyingshang';
		},addGongyingshangURL:function(){
			return path + '/gongyingshang/xinjiangys';
		}
	},
	init: function(){
		gongyingshangnew.bandFunction();
	},
	getinsertMsg: function(){
		
	},
	getmsg: function(){
		
	},
	find: function(){
		
	},
	//绑定的方法
	bandFunction: function(){
		// 二级导航
		var A = 0;
		$(".nav-clinic-info").click(function(){	
			if(A>0){
				//confirm("编辑内容没有保存，是否离开？");
				if(confirm("编辑内容没有保存，是否离开？")){
					A = 0;
					$(".s-m-nav .g-left-nav li span").css("border","none");
		            $(this).css("border","solid 1px #00b472");
		            window.location.href = path+"/views/zhensuo/zhensuo.jsp?navMingChen="+$(this).text();
					return false;
				}else{
					return false;
				};
			};
			$(".s-m-nav .g-left-nav li span").css("border","none");
	        $(this).css("border","solid 1px #00b472");
	        window.location.href = path+"/views/zhensuo/zhensuo.jsp?navMingChen="+$(this).text();
		})
		// 科室管理
		$(".nav-keshi").click(function(){
			if(A>0){
				if(confirm("编辑内容没有保存，是否离开？")){
					A = 0;
					$(".s-m-nav .g-left-nav li span").css("border","none");
		            $(this).css("border","solid 1px #00b472");
		            window.location.href = path+"/views/zhensuo/zhensuo.jsp?navMingChen="+$(this).text();
					return false;
				}else{
					return false;
				};
			};
			$(".s-m-nav .g-left-nav li span").css("border","none");
	        $(this).css("border","solid 1px #00b472");
	        window.location.href = path+"/views/zhensuo/zhensuo.jsp?navMingChen="+$(this).text();
		})
		$(".nav-staff-info").click(function(){
			if(A>0){
				if(confirm("编辑内容没有保存，是否离开？")){
					A = 0;
					$(".s-m-nav .g-left-nav li span").css("border","none");
		            $(this).css("border","solid 1px #00b472");
		            window.location.href = path+"/views/zhensuo/zhensuo.jsp?navMingChen="+$(this).text();
					return false;
				}else{
					return false;
				};
			};
			$(".s-m-nav .g-left-nav li span").css("border","none");
	        $(this).css("border","solid 1px #00b472");
	        window.location.href = path+"/views/zhensuo/zhensuo.jsp?navMingChen="+$(this).text();
		})
		$(".nav-prescription-template").click(function(){
			if(A>0){
				if(confirm("编辑内容没有保存，是否离开？")){
					A = 0;
					$(".s-m-nav .g-left-nav li span").css("border","none");
		            $(this).css("border","solid 1px #00b472");
		            window.location.href = path+"/views/zhensuo/zhensuo.jsp?navMingChen="+$(this).text();
					return false;
				}else{
					return false;
				};
			};
			$(".s-m-nav .g-left-nav li span").css("border","none");
	        $(this).css("border","solid 1px #00b472");
	        window.location.href = path+"/views/zhensuo/zhensuo.jsp?navMingChen="+$(this).text();
		})
		$(".advice-template").click(function(){
			if(A>0){
				if(confirm("编辑内容没有保存，是否离开？")){
					A = 0;
					$(".s-m-nav .g-left-nav li span").css("border","none");
		            $(this).css("border","solid 1px #00b472");
		            window.location.href = path+"/views/zhensuo/zhensuo.jsp?navMingChen="+$(this).text();
					return false;
				}else{
					return false;
				};
			};
			$(".s-m-nav .g-left-nav li span").css("border","none");
	        $(this).css("border","solid 1px #00b472");
	        window.location.href = path+"/views/zhensuo/zhensuo.jsp?navMingChen="+$(this).text();
		})
		$(".test-items").click(function(){
			if(A>0){
				if(confirm("编辑内容没有保存，是否离开？")){
					A = 0;
					$(".s-m-nav .g-left-nav li span").css("border","none");
		            $(this).css("border","solid 1px #00b472");
		            window.location.href = path+"/views/zhensuo/zhensuo.jsp?navMingChen="+$(this).text();
					return false;
				}else{
					return false;
				};
				
			};
			$(".s-m-nav .g-left-nav li span").css("border","none");
	        $(this).css("border","solid 1px #00b472");
	        window.location.href = path+"/views/zhensuo/zhensuo.jsp?navMingChen="+$(this).text();
		})
		$(".addition-free").click(function(){
			if(A>0){
				if(confirm("编辑内容没有保存，是否离开？")){
					A = 0;
					$(".s-m-nav .g-left-nav li span").css("border","none");
		            $(this).css("border","solid 1px #00b472");
		            window.location.href = path+"/views/zhensuo/zhensuo.jsp?navMingChen="+$(this).text();
					return false;
				}else{
					return false;
				};
			};
			$(".s-m-nav .g-left-nav li span").css("border","none");
	        $(this).css("border","solid 1px #00b472");
	        window.location.href = path+"/views/zhensuo/zhensuo.jsp?navMingChen="+$(this).text();
		})
		//病种目录
		$(".bingzhongml").click(function(){
			if(A>0){
				if(confirm("编辑内容没有保存，是否离开？")){
					A = 0;
					$(".s-m-nav .g-left-nav li span").css("border","none");
		            $(this).css("border","solid 1px #00b472");
		            window.location.href = path+"/views/zhensuo/zhensuo.jsp?navMingChen="+$(this).text();
					return false;
				}else{
					return false;
				};
			};
			$(".s-m-nav .g-left-nav li span").css("border","none");
	        $(this).css("border","solid 1px #00b472");
	        window.location.href = path+"/views/zhensuo/zhensuo.jsp?navMingChen="+$(this).text();
		})
		$(".gongyingshang").click(function(){
			if(A>0){
				if(confirm("编辑内容没有保存，是否离开？")){
					A = 0;
					$(".s-m-nav .g-left-nav li span").css("border","none");
		            $(this).css("border","solid 1px #00b472");
					$("#cedan").html();
					window.location.href = path+"/views/zhensuo/gongyingshang/gongyingshang.jsp";
					return false;
				}else{
					return false;
				};
			};
			$(".s-m-nav .g-left-nav li span").css("border","none");
	        $(this).css("border","solid 1px #00b472");
	        $("#cedan").html();
	        window.location.href = path+"/views/zhensuo/gongyingshang/gongyingshang.jsp";
		});
		
		//下拉
		$(document).on('click','.gysul li',function(){
			var $val = $(this).attr('index');
			var str=$val.split(",");
			$('#gongysmc').val(str[0]);
			$('#dizhi').val(str[1]);
			$(this).parent('.gysul').css('display','none');
		});
		//供应商名称检索
		$(document).on('input', '#gongysmc', function () {
			//gongyingshangnew.getZdGongyzdingshang();
			if($(this).val() != ''){
				gongyingshangnew.getZdGongyzdingshang();
			}else {
				$('#gongyingsmcul').html('');
			}
		});
		
		$('#formSave').validator({
			stopOnError:"true", // 停留当前项
			ignore:":hidden",  //隐藏的不验证
			fields: {
				'mingcheng': '供应商:length[~100];required;',
				'lianxiren': '联系人:length[~64];',
				'lianxirdh': '联系电话:length[~15];',
				'dizhi': '地址:length[~100];',
				'kaihuhang': '开户行:length[~200];',
				'beizhu': '备注:length[~512];',
			}
		});
		
		//新建供应商
		$(document).on('click','#btnGongyingshangAdd',function () {
			//$('#btnGongyingshangAdd').attr('disabled', true);
			console.log($('#formSave').serialize());
			if($('#gongysmc').val() == ''){
				notifyWarning('供应商不能为空');
				$('#gongysmc').addClass("n-invalid");
				return false;
			}
			if($('#gongysmc').val().length > 100){
				notifyWarning('请最多填写100个字符');
				$('#gongysmc').addClass("n-invalid");
				return false;
			}
			if($('#lianxiren').val().length > 64){
				notifyWarning('请最多填写64个字符');
				$('#lianxiren').addClass("n-invalid");
				return false;
			}
			if($('#lianxirdh').val().length > 15){
				notifyWarning('请最多填写15个字符');
				$('#lianxirdh').addClass("n-invalid");
				return false;
			}
			if($('#dizhi').val().length > 100){
				notifyWarning('请最多填写100个字符');
				$('#dizhi').addClass("n-invalid");
				return false;
			}
			if($('#kaihuhang').val().length > 200){
				notifyWarning('请最多填写200个字符');
				$('#kaihuhang').addClass("n-invalid");
				return false;
			}
			if($('#yinhangzh').val().length > 20){
				notifyWarning('请最多填写20个字符');
				$('#yinhangzh').addClass("n-invalid");
				return false;
			}
			if($('#beizhu').val().length > 512){
				notifyWarning('请最多填写512个字符');
				$('#beizhu').addClass("n-invalid");
				return false;
			}
			$.ajax({
				url: gongyingshangnew.url.addGongyingshangURL(),
				type: 'post',
				data: $('#formSave').serialize(),
				success: function(data) {
				//判断是否请求成功
				if(data.succsess == true){
					if(data.data=="success"){
						var presuccmsg=encodeURI(encodeURI('供应商保存成功'));
						$('#btnGongyingshangAdd').attr('disabled',false);
						var sjc =new Date().getTime();
						window.location.href = path+ "/views/zhensuo/gongyingshang/gongyingshang.jsp?msg=" + presuccmsg + "&sjc=" + sjc;
					}else{
						$('#btnGongyingshangAdd').removeAttr('disabled');
						notifyWarning(data.data);
					}
				}else { 
					$('#btnGongyingshangAdd').removeAttr('disabled');
					notifyWarning(data);
				}
				
				}
			});
		});
		//返回
		$(document).on('click','#fanhui',function () {
			window.location.href = path+ "gongyingshang.jsp";
		});
		
		// radio 单选框
		$("label[name='chinese']").click(function(){
			$("label[name='europe']").removeClass("on");
			$("label[name='chinese']").addClass("on");
			$('input[name="jinyongbz"]').val('0');
		});
		$("label[name='europe']").click(function(){
			$("label[name='chinese']").removeClass("on");
			$("label[name='europe']").addClass("on");
			$('input[name="jinyongbz"]').val('1');
		});
	},getZdGongyzdingshang(){//检索字典供应商
		var val = $('#gongysmc').val();
		if(val!=''){
			$.ajax({
				url: gongyingshangnew.url.zdGongyingshangURL(),
				type:'post',
				data:{"strParams":val},
				success:function(data) {
					var str = "";
					if(data != '') {
						$(data).each(function(){
						       console.log(data);
							str+='<li index="'+this.mingcheng+','+this.dizhi+'">'+this.mingcheng+'</li>';
						});
					} 
					$('#gongyingsmcul').html("");
					$('#gongyingsmcul').html(str);
				}
			});
		}
	}
}